//
//  NeedCenterViewController.m
//  ForestPack
//
//  Created by 郑洲 on 2018/7/5.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "NeedCenterViewController.h"

#import "SearchViewController.h"
#import "PublishNeedViewController.h"
#import "FPOrderDetailVC.h"

//cell
#import "NeedCenterTableViewCell.h"

@interface NeedCenterViewController ()<UIScrollViewDelegate, UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UIView        * moveLine;
@property (nonatomic, strong) UIButton      * selectBtn;
@property (nonatomic, strong) UIScrollView  * scrollView;

///全部
@property (nonatomic,strong)  NSArray                * allDataArray;
@property (nonatomic,strong)  CustomDemandHallModel  * allCustomDemandHallModel;
///系统
@property (nonatomic,strong)  NSArray                * systemDataArray;
@property (nonatomic,strong)  CustomDemandHallModel  * systemCustomDemandHallModel;
///竞标
@property (nonatomic,strong)  NSArray                * biddingArray;
@property (nonatomic,strong)  CustomDemandHallModel  * biddingCustomDemandHallModel;
///比稿
@property (nonatomic,strong)  NSArray                * compareArray;
@property (nonatomic,strong)  CustomDemandHallModel  * compareCustomDemandHallModel;
///计件
@property (nonatomic,strong)  NSArray                * countArray;
@property (nonatomic,strong)  CustomDemandHallModel  * countCustomDemandHallModel;

@property (nonatomic,assign) NSInteger   current_page;
@property (nonatomic,assign) NSInteger   tempIndex;

@end

@implementation NeedCenterViewController

- (NSArray *)allDataArray
{
    if (_allDataArray == nil) {
        _allDataArray = [[NSArray alloc] init];
    }
    return _allDataArray;
}

- (NSArray *)biddingArray
{
    if (_biddingArray == nil) {
        _biddingArray = [[NSArray alloc] init];
    }
    return _biddingArray;
}

- (NSArray *)compareArray
{
    if (_compareArray == nil) {
        _compareArray = [[NSArray alloc] init];
    }
    return _compareArray;
}

- (NSArray *)countArray
{
    if (_countArray == nil) {
        _countArray = [[NSArray alloc] init];
    }
    return _countArray;
}

- (NSArray *)systemDataArray
{
    if (_systemDataArray == nil) {
        _systemDataArray = [[NSArray alloc] init];
    }
    return _systemDataArray;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setShadowImage:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"需求大厅";
    self.tempIndex = -1;
    [self setNavBar];
    [self setTopBar];
    [self setUI];

    [self getAllDataFromServer];
    [self getSystemDataFromServer];
    [self getBiddingDataFromServer];
    [self getCompareDataFromServer];
    [self getCountDataFromServer];
}

#pragma mark - 全部
- (void)getAllDataFromServer
{
    BaseTableView * tableView = [self.scrollView viewWithTag:2000];
    
    NSString * url = [NSString stringWithFormat:@"%@app/demand_hall",REQUESTHEADER];
    NSDictionary * parameter = @{@"token":kNSUDefaultReadKey(@"token")};//,@"type":@11
    [HttpManager showWait];
    [HttpManager postHttpRequestByPost:url andParameter:parameter success:^(id successResponse) {
        [HttpManager hideWait];
        [tableView.mj_header endRefreshing];
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        NSDictionary *dict = successResponse;
        if ([status isEqualToString:@"1"]) {
            NSError *error;
            // 成功
            self.allCustomDemandHallModel = [[CustomDemandHallModel alloc] initWithDictionary:dict[@"data"] error:&error];
            
            if (self.allCustomDemandHallModel != nil) {
                self.allDataArray = self.allCustomDemandHallModel.data;
                [tableView reloadData];
            }
        }else{
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [tableView.mj_header endRefreshing];
        [HttpManager showFail];
    }];
}

- (void)getAllMoreDataFromServer
{
    BaseTableView * tableView = [self.scrollView viewWithTag:2000];
    
    if (!self.allCustomDemandHallModel.current_page) {
        [tableView.mj_footer endRefreshing];
        return;
    }
    self.current_page = [self.allCustomDemandHallModel.current_page integerValue];
    self.current_page += 1;
    
    NSString * url = [NSString stringWithFormat:@"%@app/demand_hall",REQUESTHEADER];
    NSDictionary * parameter = @{@"token":kNSUDefaultReadKey(@"token")};//,@"type":@11
    [HttpManager showWait];
    [HttpManager postHttpRequestByPost:url andParameter:parameter success:^(id successResponse) {
        [HttpManager hideWait];
        [tableView.mj_header endRefreshing];
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        NSDictionary *dict = successResponse;
        if ([status isEqualToString:@"1"]) {
            NSError *error;
            // 成功
            self.allCustomDemandHallModel = [[CustomDemandHallModel alloc] initWithDictionary:dict[@"data"] error:&error];
            if (self.allCustomDemandHallModel != nil) {
                self.allDataArray = [self.allDataArray arrayByAddingObjectsFromArray:self.allCustomDemandHallModel.data];
                if (self.allCustomDemandHallModel.data.count <= 0) {
                    [tableView.mj_footer endRefreshingWithNoMoreData];
                }
                [tableView reloadData];
            }
        }else{
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [tableView.mj_header endRefreshing];
        [HttpManager showFail];
    }];
}


#pragma mark - 需求
- (void)getSystemDataFromServer
{
    BaseTableView * tableView = [self.scrollView viewWithTag:2001];
    
    NSString * url = [NSString stringWithFormat:@"%@app/demand_hall",REQUESTHEADER];
    NSDictionary * parameter = @{@"token":kNSUDefaultReadKey(@"token")};//,@"type":@11
    [HttpManager showWait];
    [HttpManager postHttpRequestByPost:url andParameter:parameter success:^(id successResponse) {
        [HttpManager hideWait];
        [tableView.mj_header endRefreshing];
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        NSDictionary *dict = successResponse;
        if ([status isEqualToString:@"1"]) {
            NSError *error;
            // 成功
            self.systemCustomDemandHallModel = [[CustomDemandHallModel alloc] initWithDictionary:dict[@"data"] error:&error];
            
            if (self.systemCustomDemandHallModel != nil) {
//                self.systemDataArray = self.systemCustomDemandHallModel.data;
                [tableView reloadData];
            }
        }else{
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [tableView.mj_header endRefreshing];
        [HttpManager showFail];
    }];
}

- (void)getSystemMoreDataFromServer
{
    BaseTableView * tableView = [self.scrollView viewWithTag:2001];
    if (!self.systemCustomDemandHallModel.current_page) {
        [tableView.mj_footer endRefreshing];
        return;
    }
    self.current_page = [self.systemCustomDemandHallModel.current_page integerValue];
    self.current_page += 1;
    
    NSString * url = [NSString stringWithFormat:@"%@app/demand_hall",REQUESTHEADER];
    NSDictionary * parameter = @{@"token":kNSUDefaultReadKey(@"token"),@"type":@11};//,@"type":@11
    [HttpManager showWait];
    [HttpManager postHttpRequestByPost:url andParameter:parameter success:^(id successResponse) {
        [HttpManager hideWait];
        [tableView.mj_header endRefreshing];
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        NSDictionary *dict = successResponse;
        if ([status isEqualToString:@"1"]) {
            NSError *error;
            // 成功
            self.systemCustomDemandHallModel = [[CustomDemandHallModel alloc] initWithDictionary:dict[@"data"] error:&error];
            if (self.systemCustomDemandHallModel != nil) {
//                self.systemDataArray = [self.systemDataArray arrayByAddingObjectsFromArray:self.systemCustomDemandHallModel.data];
                if (self.systemCustomDemandHallModel.data.count <= 0) {
                    [tableView.mj_footer endRefreshingWithNoMoreData];
                }
                [tableView reloadData];
            }
        }else{
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [tableView.mj_header endRefreshing];
        [HttpManager showFail];
    }];
}

#pragma mark - 竞标
- (void)getBiddingDataFromServer
{
    BaseTableView * tableView = [self.scrollView viewWithTag:2002];
    
    NSString * url = [NSString stringWithFormat:@"%@app/demand_hall",REQUESTHEADER];
    NSDictionary * parameter = @{@"token":kNSUDefaultReadKey(@"token"),@"type":@11};//,@"type":@11
    [HttpManager showWait];
    [HttpManager postHttpRequestByPost:url andParameter:parameter success:^(id successResponse) {
        [HttpManager hideWait];
        [tableView.mj_header endRefreshing];
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        NSDictionary *dict = successResponse;
        if ([status isEqualToString:@"1"]) {
            NSError *error;
            // 成功
            self.biddingCustomDemandHallModel = [[CustomDemandHallModel alloc] initWithDictionary:dict[@"data"] error:&error];
            
            if (self.biddingCustomDemandHallModel != nil) {
                self.biddingArray = self.biddingCustomDemandHallModel.data;
                [tableView reloadData];
            }
        }else{
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [tableView.mj_header endRefreshing];
        [HttpManager showFail];
    }];
}

- (void)getBiddingMoreDataFromServer
{
    BaseTableView * tableView = [self.scrollView viewWithTag:2002];
    
    if (!self.biddingCustomDemandHallModel.current_page) {
        [tableView.mj_footer endRefreshing];
        return;
    }
    self.current_page = [self.biddingCustomDemandHallModel.current_page integerValue];
    self.current_page += 1;
    
    NSString * url = [NSString stringWithFormat:@"%@app/demand_hall",REQUESTHEADER];
    NSDictionary * parameter = @{@"token":kNSUDefaultReadKey(@"token"),@"type":@11};//,@"type":@11
    [HttpManager showWait];
    [HttpManager postHttpRequestByPost:url andParameter:parameter success:^(id successResponse) {
        [HttpManager hideWait];
        [tableView.mj_header endRefreshing];
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        NSDictionary *dict = successResponse;
        if ([status isEqualToString:@"1"]) {
            NSError *error;
            // 成功
            self.biddingCustomDemandHallModel = [[CustomDemandHallModel alloc] initWithDictionary:dict[@"data"] error:&error];
            if (self.biddingCustomDemandHallModel != nil) {
                self.biddingArray = [self.biddingArray arrayByAddingObjectsFromArray:self.biddingCustomDemandHallModel.data];
                if (self.biddingCustomDemandHallModel.data.count <= 0) {
                    [tableView.mj_footer endRefreshingWithNoMoreData];
                }
                [tableView reloadData];
            }
        }else{
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [tableView.mj_header endRefreshing];
        [HttpManager showFail];
    }];
}

#pragma mark - 比稿
- (void)getCompareDataFromServer
{
    BaseTableView * tableView = [self.scrollView viewWithTag:2003];
    
    NSString * url = [NSString stringWithFormat:@"%@app/demand_hall",REQUESTHEADER];
    NSDictionary * parameter = @{@"token":kNSUDefaultReadKey(@"token"),@"type":@12};//,@"type":@11
    [HttpManager showWait];
    [HttpManager postHttpRequestByPost:url andParameter:parameter success:^(id successResponse) {
        [HttpManager hideWait];
        [tableView.mj_header endRefreshing];
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        NSDictionary *dict = successResponse;
        if ([status isEqualToString:@"1"]) {
            NSError *error;
            // 成功
            self.compareCustomDemandHallModel = [[CustomDemandHallModel alloc] initWithDictionary:dict[@"data"] error:&error];
            
            if (self.compareCustomDemandHallModel != nil) {
                self.compareArray = self.compareCustomDemandHallModel.data;
                [tableView reloadData];
            }
        }else{
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [tableView.mj_header endRefreshing];
        [HttpManager showFail];
    }];
}

- (void)getCompareMoreDataFromServer
{
    BaseTableView * tableView = [self.scrollView viewWithTag:2003];
    
    if (!self.compareCustomDemandHallModel.current_page) {
        [tableView.mj_footer endRefreshing];
        return;
    }
    self.current_page = [self.compareCustomDemandHallModel.current_page integerValue];
    self.current_page += 1;
    
    NSString * url = [NSString stringWithFormat:@"%@app/demand_hall",REQUESTHEADER];
    NSDictionary * parameter = @{@"token":kNSUDefaultReadKey(@"token"),@"type":@12};//,@"type":@11
    [HttpManager showWait];
    [HttpManager postHttpRequestByPost:url andParameter:parameter success:^(id successResponse) {
        [HttpManager hideWait];
        [tableView.mj_header endRefreshing];
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        NSDictionary *dict = successResponse;
        if ([status isEqualToString:@"1"]) {
            NSError *error;
            // 成功
            self.compareCustomDemandHallModel = [[CustomDemandHallModel alloc] initWithDictionary:dict[@"data"] error:&error];
            if (self.compareCustomDemandHallModel != nil) {
                self.compareArray = [self.compareArray arrayByAddingObjectsFromArray:self.compareCustomDemandHallModel.data];
                if (self.compareCustomDemandHallModel.data.count <= 0) {
                    [tableView.mj_footer endRefreshingWithNoMoreData];
                }
                [tableView reloadData];
            }
        }else{
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [tableView.mj_header endRefreshing];
        [HttpManager showFail];
    }];
}

#pragma mark - 计件
- (void)getCountDataFromServer
{
    BaseTableView * tableView = [self.scrollView viewWithTag:2004];
    
    NSString * url = [NSString stringWithFormat:@"%@app/demand_hall",REQUESTHEADER];
    NSDictionary * parameter = @{@"token":kNSUDefaultReadKey(@"token"),@"type":@13};//,@"type":@11
    [HttpManager showWait];
    [HttpManager postHttpRequestByPost:url andParameter:parameter success:^(id successResponse) {
        [HttpManager hideWait];
        [tableView.mj_header endRefreshing];
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        NSDictionary *dict = successResponse;
        if ([status isEqualToString:@"1"]) {
            NSError *error;
            // 成功
            self.countCustomDemandHallModel = [[CustomDemandHallModel alloc] initWithDictionary:dict[@"data"] error:&error];
            
            if (self.countCustomDemandHallModel != nil) {
                self.countArray = self.countCustomDemandHallModel.data;
                [tableView reloadData];
            }
        }else{
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [tableView.mj_header endRefreshing];
        [HttpManager showFail];
    }];
}

- (void)getCountMoreDataFromServer
{
    BaseTableView * tableView = [self.scrollView viewWithTag:2004];
    
    if (!self.countCustomDemandHallModel.current_page) {
        [tableView.mj_footer endRefreshing];
        return;
    }
    self.current_page = [self.countCustomDemandHallModel.current_page integerValue];
    self.current_page += 1;
    
    NSString * url = [NSString stringWithFormat:@"%@app/demand_hall",REQUESTHEADER];
    NSDictionary * parameter = @{@"token":kNSUDefaultReadKey(@"token"),@"type":@13};//,@"type":@11
    [HttpManager showWait];
    [HttpManager postHttpRequestByPost:url andParameter:parameter success:^(id successResponse) {
        [HttpManager hideWait];
        [tableView.mj_header endRefreshing];
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        NSDictionary *dict = successResponse;
        if ([status isEqualToString:@"1"]) {
            NSError *error;
            // 成功
            self.countCustomDemandHallModel = [[CustomDemandHallModel alloc] initWithDictionary:dict[@"data"] error:&error];
            if (self.countCustomDemandHallModel != nil) {
                self.countArray = [self.countArray arrayByAddingObjectsFromArray:self.countCustomDemandHallModel.data];
                if (self.countCustomDemandHallModel.data.count <= 0) {
                    [tableView.mj_footer endRefreshingWithNoMoreData];
                }
                [tableView reloadData];
            }
        }else{
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [tableView.mj_header endRefreshing];
        [HttpManager showFail];
    }];
}

- (void)setNavBar
{
    UIButton *searchBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
    [searchBtn setImage:[UIImage imageNamed:@"搜索白色"] forState:UIControlStateNormal];
    searchBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
    [searchBtn addTarget:self action:@selector(turnToSearch) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *searchItem = [[UIBarButtonItem alloc] initWithCustomView:searchBtn];
    
    UIButton *editBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
    [editBtn setImage:[UIImage imageNamed:@"编辑白色"] forState:UIControlStateNormal];
    editBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 25, 0, 0);
    [editBtn addTarget:self action:@selector(turnToAdd) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *editItem = [[UIBarButtonItem alloc] initWithCustomView:editBtn];
    
    self.navigationItem.rightBarButtonItems = @[searchItem, editItem];
}

- (void)turnToSearch
{
    SearchViewController *vc = [[SearchViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)turnToAdd
{
    PublishNeedViewController *vc = [[PublishNeedViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)setTopBar
{
    UIView *topBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ScreenX375(30))];
    topBar.backgroundColor = RGB_COLOR(235, 67, 90);
    [self.view addSubview:topBar];
    
    NSArray *nameArr = @[@"全部",@"系统订单",@"竞标单",@"比稿",@"计件"];
    for (int i = 0; i < nameArr.count; i++) {
        UIButton *typeBtn = [[UIButton alloc] initWithFrame:CGRectMake(i * SCREEN_WIDTH / nameArr.count, 0, SCREEN_WIDTH / nameArr.count, ScreenX375(30))];
        [typeBtn setTitle:nameArr[i] forState:UIControlStateNormal];
        [typeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        [typeBtn setTitleColor:RGBACOLOR(255, 255, 255, 0.6) forState:UIControlStateNormal];
        typeBtn.titleLabel.font = Kfont(16);
        typeBtn.tag = 100 + i;
        if (i == 0) {
            typeBtn.selected = YES;
            _selectBtn = typeBtn;
        }
        
        [typeBtn addTarget:self action:@selector(typeClick:) forControlEvents:UIControlEventTouchUpInside];
        [topBar addSubview:typeBtn];
    }
    
    self.moveLine = [[UIView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH / nameArr.count - ScreenX375(30)) / 2, ScreenX375(30) - 2, ScreenX375(30), 2)];
    self.moveLine.backgroundColor = [UIColor whiteColor];
    [topBar addSubview:self.moveLine];
}

- (void)typeClick:(UIButton *)button
{
    self.tempIndex = button.tag - 100;
    [self refreshTableViewWith:self.tempIndex];
    _selectBtn.selected = NO;
    button.selected = YES;
    _selectBtn = button;
    [UIView animateWithDuration:0.2 animations:^{
        self.moveLine.frame = CGRectMake((SCREEN_WIDTH / 5 - ScreenX375(30)) / 2 + (button.tag - 100) * SCREEN_WIDTH / 5, ScreenX375(30) - 2, ScreenX375(30), 2);
    }];
    [_scrollView setContentOffset:CGPointMake((button.tag - 100) * SCREEN_WIDTH, 0) animated:YES];
    
}

- (void)setUI
{
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, ScreenX375(30), SCREEN_WIDTH, SCREEN_HEIGHT - ScreenX375(30))];
    self.scrollView.showsVerticalScrollIndicator = false;
    self.scrollView.showsHorizontalScrollIndicator = false;
    self.scrollView.pagingEnabled = true;
    self.scrollView.delegate = self;
    self.scrollView.contentSize = CGSizeMake(SCREEN_WIDTH * 5, 0);
    [self.view addSubview:self.scrollView];
    
    for (int i = 0; i < 5; i++) {
        BaseTableView * tableView = [[BaseTableView alloc] initWithFrame:CGRectMake(i * SCREEN_WIDTH, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAVIGATION_BAR_HEIGHT - ScreenX375(30))];
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.backgroundColor = [UIColor whiteColor];
        tableView.tag = 2000 + i;
        tableView.rowHeight = ScreenX375(72);
        [self.scrollView addSubview:tableView];
        
        [self setRefreshTableView:tableView];
    }
}

-(void)setRefreshTableView:(BaseTableView *)tableView
{
    WeakObj(self);
    tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        selfWeak.current_page = 1;
        switch (tableView.tag) {
            case 2000:
                [selfWeak getAllDataFromServer];
                break;
            case 2001:
                [selfWeak getSystemDataFromServer];
                break;
            case 2002:
                [selfWeak getBiddingDataFromServer];
                break;
            case 2003:
                [selfWeak getCompareDataFromServer];
                break;
            case 2004:
                [selfWeak getCountDataFromServer];
                break;
        }
    }];
    
    tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        
        switch (tableView.tag) {
            case 2000:
                [selfWeak getAllMoreDataFromServer];
                break;
            case 2001:
                [selfWeak getSystemMoreDataFromServer];
                break;
            case 2002:
                [selfWeak getBiddingMoreDataFromServer];
                break;
            case 2003:
                [selfWeak getCompareMoreDataFromServer];
                break;
            case 2004:
                [selfWeak getCountMoreDataFromServer];
                break;
        }
    }];
}


#pragma mark - UITableViewDelegate,DataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (tableView.tag == 2000) {
        return self.allDataArray.count;
    }else if (tableView.tag == 2001)
    {
        return self.systemDataArray.count;
    }else if (tableView.tag == 2002)
    {
        return self.biddingArray.count;
    }else if (tableView.tag == 2003)
    {
        return self.compareArray.count;
    }else{
        return self.countArray.count;
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NeedCenterTableViewCell *cell = [NeedCenterTableViewCell cellWithTableView:tableView andIndexPath:indexPath];
    
    if (tableView.tag == 2000) {
        cell.customDemandHallDataModel = self.allDataArray[indexPath.section];
    }else if (tableView.tag == 2001)
    {
        cell.customDemandHallDataModel = self.systemDataArray[indexPath.section];
    }else if (tableView.tag == 2002)
    {
        cell.customDemandHallDataModel = self.biddingArray[indexPath.section];
    }else if (tableView.tag == 2003)
    {
        cell.customDemandHallDataModel = self.compareArray[indexPath.section];
    }else{
        cell.customDemandHallDataModel = self.countArray[indexPath.section];
    }
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return ScreenX375(10);
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ScreenX375(10))];
    view.backgroundColor = TABLEVIEW_BACKGROUNDCOLOR;
    return view;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:true];
    FPOrderDetailVC *vc = [[FPOrderDetailVC alloc] init];
    
    if (tableView.tag == 2000) {
        CustomDemandHallDataModel * model = self.allDataArray[indexPath.section];
        vc.Id = model.Id;
    }else if (tableView.tag == 2001)
    {
        CustomDemandHallDataModel * model = self.systemDataArray[indexPath.section];
        vc.Id = model.Id;
    }else if (tableView.tag == 2002)
    {
        CustomDemandHallDataModel * model = self.biddingArray[indexPath.section];
        vc.Id = model.Id;
    }else if (tableView.tag == 2003)
    {
        CustomDemandHallDataModel * model = self.compareArray[indexPath.section];
        vc.Id = model.Id;
    }else{
        CustomDemandHallDataModel * model = self.countArray[indexPath.section];
        vc.Id = model.Id;
    }

    [self.navigationController pushViewController:vc animated:true];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView == _scrollView) {
        NSInteger index = scrollView.contentOffset.x / SCREEN_WIDTH;
        
        if (self.tempIndex != index) {
            self.tempIndex = index;
            [self refreshTableViewWith:index];
            UIButton *button = [self.view viewWithTag:index + 100];
            _selectBtn.selected = NO;
            button.selected = YES;
            _selectBtn = button;
            [UIView animateWithDuration:0.2 animations:^{
                self.moveLine.frame = CGRectMake((SCREEN_WIDTH / 5 - ScreenX375(30)) / 2 + (button.tag - 100) * SCREEN_WIDTH / 5, ScreenX375(30) - 2, ScreenX375(30), 2);
            }];
        }
        
        
    }
}

- (void)refreshTableViewWith:(NSInteger)tag
{
    BaseTableView * tableView = [self.scrollView viewWithTag:2000+tag];
    [tableView.mj_header endRefreshing];
}


@end
